package com.etool.action.auth;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;

import com.etool.commons.utils.AjaxUtils;
import com.etool.modules.auth.model.AuthWorker;
import com.etool.modules.auth.service.CurrentWorkerAware;
import com.etool.modules.curd.service.CurdService;
import com.opensymphony.xwork2.ActionSupport;

public class MenuAction extends ActionSupport implements CurrentWorkerAware{
	
	private HttpServletResponse response=ServletActionContext.getResponse();
	
	private AuthWorker authWorker;
	
	private CurdService curdService;
	
	/**
	 * 读取菜单树-最顶层菜单
	 * @return
	 */
	@Action("read-menu-root")
	public String readMenuRoot()
	{
		List<Map<String, Object>> result= curdService.read("auth_menu", Collections.singletonMap("_parentId", (Object)0),"id");
		
		AjaxUtils.writeJson(response, Collections.singletonMap("result", (Object)result));
		
		return NONE;
	}
	
	
	/**
	 * 读取菜单树-所有
	 * @return
	 */
	@Action("read-menu")
	public String readMenu()
	{
		List<Map<String, Object>> result= curdService.read("auth_menu", null);
		
		AjaxUtils.writeJson(response, Collections.singletonMap("result", (Object)result));
		
		return NONE;
	}

	public void setAuthWorker(AuthWorker authWorker) {
		this.authWorker=authWorker;
	}

	public CurdService getCurdService() {
		return curdService;
	}

	public void setCurdService(CurdService curdService) {
		this.curdService = curdService;
	}
	
	
}
